<?php
App::uses('AppController', 'Controller');
/**
 * Removalreasons Controller
 *
 * @property Removalreason $Removalreason
 */
class RemovalreasonsController extends AppController {

/**
 * index method
 *
 * @return void
 */

	public function index() {
		$this->Removalreason->recursive = 0;
		$this->set('removalreasons', $this->paginate(array('archive' => '0')));
	}

/**
 * view method
 *
 * @throws NotFoundException
 * @param string $id
 * @return void
 */
	public function view($id = null) {
		if (!$this->Removalreason->exists($id)) {
			throw new NotFoundException(__('Invalid Removal Reason'));
		}
		$options = array('conditions' => array('Removalreason.' . $this->Removalreason->primaryKey => $id));
		$this->set('removalreason', $this->Removalreason->find('first', $options));
	}

/**
 * add method
 *
 * @return void
 */
	public function add() {
		if ($this->request->is('post')) {
			$this->Removalreason->create();
			if ($this->Removalreason->save($this->request->data)) {
				$this->Session->setFlash(__('The Removal Reason has been saved'),'default', array('class' => 'savesuccess'));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('This Removal Reason could not be saved. Please, try again.'),'default', array('class' => 'saveerror'));
			}
		}
	}

/**
 * edit method
 *
 * @throws NotFoundException
 * @param string $id
 * @return void
 */
	public function edit($id = null) {
		if (!$this->Removalreason->exists($id)) {
			throw new NotFoundException(__('Invalid Removal Reason'));
		}
		if ($this->request->is('post') || $this->request->is('put')) {
			if ($this->Removalreason->save($this->request->data)) {
				$this->Session->setFlash(__('The Removal Reason has been saved'),'default', array('class' => 'savesuccess'));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('This Removal Reason could not be saved. Please, try again.'),'default', array('class' => 'saveerror'));
			}
		} else {
			$options = array('conditions' => array('Removalreason.' . $this->Removalreason->primaryKey => $id));
			$this->request->data = $this->Removalreason->find('first', $options);
		}
	}

/**
 * delete method
 *
 * @throws NotFoundException
 * @throws MethodNotAllowedException
 * @param string $id
 * @return void
 */
	public function delete($id = null) {
		$this->Removalreason->id = $id;
		if (!$this->Removalreason->exists()) {
			throw new NotFoundException(__('Invalid Removal Reason'));
		}
		$this->request->onlyAllow('post', 'delete');
		$data = array('id' => $id, 'archive' => '1');
		if ($this->Removalreason->save($data)) {
			$this->Session->setFlash(__('Removal Reason deleted'),'default', array('class' => 'savesuccess'));
			$this->redirect(array('action' => 'index'));
		}
		$this->Session->setFlash(__('Removal Reason was not deleted'),'default', array('class' => 'saveerror'));
		$this->redirect(array('action' => 'index'));
	}
}
